<?php
namespace Admin\Controller;
use Think\Controller;
class LoginController extends Controller {
    public function index(){
    	layout(false);
        $this->display();
    }
    public function ajax_login() {
    	if(IS_POST) {
			$username = I("post.username");
			$password = I("post.password");
			$remember = I("post.remember");
			$model = M("admin");
			if($data = $model->where("username = '$username'")->find()) {
				if($data["password"] == $password) {
					if($remember) {
						cookie("username",$data["username"],1209600);
						cookie("password",$data["password"],1209600);
					}
					session("user_id", $data["id"]);
					session("username", $data["username"]);
					echo 200;
				}else {
					echo 401;
				}
			}else {
				echo 400;
			}
		}
    }
    public function ajax_exitlogin() {
		if(cookie()) {
			cookie("username",null);
			cookie("password",null);
		}
        session("user_id",null);
        session("username",null);
		redirect("index");
	}
}